﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Db8.ViewModels
{
    public static class ListPageHelper
    {
        public static ListPage<TSource> ToListPage<TSource>(this IEnumerable<TSource> source, int total, int page, int pageSize)
        {
            return new ListPage<TSource>(total, page, pageSize, source);
        }
    }
    public class ListPage<T> : List<T>
    {
        public int Total { get; set; }

        public int Page { get; set; }

        public int PageSize { get; set; }

        public bool HasMore 
        {
            get 
            {
                return (Page * PageSize + Count < Total);
            }
        }

        public ListPage(int total, int page, int pageSize)
            : base()
        {
            Total = total;
            Page = page;
            PageSize = pageSize;
        }

        public ListPage(int total, int page, int pageSize, int capacity)
            : base(capacity)
        {
            Total = total;
            Page = page;
            PageSize = pageSize;
        }

        public ListPage(int total, int page, int pageSize, IEnumerable<T> collection)
            : base(collection)
        {
            Total = total;
            Page = page;
            PageSize = pageSize;
        }

        public ListPage(IEnumerable<T> collection)
            : base(collection)
        {
            Total = this.Count;
            Page = 0;
            PageSize = this.Count;
        }

        public ListPage(int pageSize)
            : base()
        {
            Total = this.Count;
            Page = 0;
            PageSize = pageSize;
        }

    }
}